<template>
  <base-breadcrumb>
    <searchData
      :searchData="searchArr"
      @search="search"
    ></searchData>

    <a-card :bordered="false">

      <!-- <title-name title="项目部信息列表"></title-name> -->

      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px"> 项目部总数：<span class="totalNum">{{totalNum}} 个</span> |
          施工准备阶段：<span class="totalNum">{{totalDels.ongoingNum}} 个</span> |
          在建 ：<span class="totalNum">{{totalDels.startsNum	}} 个</span> |
          停工 ：<span class="totalNum">{{totalDels.shutdownNum}} 个</span> |
          停缓建 ：<span class="totalNum">{{totalDels.suspendedNum}} 个</span> |
          维保期 ：<span class="totalNum">{{totalDels.maintenancePeriodNum}} 个</span>
          维保期截止 ：<span class="totalNum">{{totalDels.maintenancePeriodCloseNum}} 个</span>
        </span>
      </div>

      <list-table
        ref="table"
        size="default"
        :rowKey="record => record.id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="status"
          slot-scope="text"
        >
          <a-badge
            :status="text | statusTypeFilter"
            :text="text | statusFilter"
          />
        </span>
        <span
          slot="description"
          slot-scope="text"
        >
          <ellipsis
            :length="8"
            tooltip
          >{{ text }}</ellipsis>
        </span>
        <span
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              @click="handleDels(record)"
              v-btnPermission="'pm_006_loo_01'"
            >查看</a>
            <template v-if="record.statusCode != 1">
             <a
                @click="handleEdit(record)"
                v-btnPermission="'pm_006_adj_02'"
              >人员调整</a>
            </template>

            <template v-if="record.statusCode == '1'  "><a
                @click="handleApproveDetail(record)"
                v-btnPermission="'pm_006_moi_03'"
              >审批信息</a>
            </template>
          </MoreButton>
        </span>
      </list-table>

      <ApprovalDetails
        :title="'审批详情'"
        :businessId="businessId"
        :visible="visibleApprove"
        @cancel="visibleApprove = false"
        @confirm="visibleApprove = false"
      />

    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getProjectsList, getProjectTotal } from '@/api/project/projects'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import ApprovalDetails from '@/components/approvalDetails'

import ARow from 'ant-design-vue/es/grid/Row'

const columns = [
  {
    title: '序号',
    width: 65,

    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '项目名称',
    width: 100,
    dataIndex: 'shortName'
  },
  {
    title: '项目编号',
    width: 100,
    dataIndex: 'projectNum'
  },
  {
    title: '分公司',
    width: 90,
    dataIndex: 'branchName'
  },
  {
    title: '当前项目部人数',
    width: 120,
    dataIndex: 'projectPeople'
  },
  {
    title: '项目经理',
    width: 100,
    dataIndex: 'realityPmName'
  },
  {
    title: '项目状态',
    width: 100,
    dataIndex: 'statusName'
  },

  {
    title: '操作',
    dataIndex: 'action',
    width: 220,
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    ApprovalDetails,
    Ellipsis
  },
  data() {
    return {
      columns,
      totalNum: '',
      searchArr: [
        // 搜索框
        // {
        //   name: '项目名称',
        //   value: 'projectName',
        //   type: 'input'
        // },
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        {
          name: '项目编号',
          value: 'projectNo',
          type: 'input'
        },
        // {
        //   name: '分公司',
        //   valueKey: 'branchCode',
        //   type: SelectSubCompany
        // },
        {
          name: '项目状态',
          value: 'statusCode',
          type: 'select',
          data: [
            {
              value: '4',
              label: '施工准备阶段'
            },
            {
              value: '5',
              label: '在建'
            },
            {
              value: '6',
              label: '停工'
            },
            {
              value: '7',
              label: '停缓建'
            },
            {
              value: '8',
              label: '维保期'
            },
            {
              value: '9',
              label: '维保期截止'
            }
          ]
        }
      ],

      // 停工附件上传
      listUrl: '',
      deleteUrl: '/cscec-project-business/file/business/project-fileDelete',
      uploadList: '/cscec-project-business/file/business/fileUpload',

      businessId: '',
      visibleApprove: false,

      // 重新开工附件上传
      listUrls: '',

      visible: false,
      title: '',

      isShow: true,

      visibles: false,
      titles: '重新开工申请',

      form: {}, // 新增停工
      forms: {}, // 重新开工申请
      queryParam: {
        isProjectPeople: 1, // 是否查询项目部人数 0 不查  1 要查
        projectStatus: '1,2,3,4,5,6'
      },

      data: [],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam, { excludeSubProject: false })
        return getProjectsList(requestParameters).then((res) => {
          this.totalNum = res.totalSize
          return res
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      reasons: [],
      totalDels: {}
    }
  },

  created() {
    this.getProjectTotal()
  },
  computed: {
    // rowSelection() {
    //   return {
    //     selectedRowKeys: this.selectedRowKeys,
    //     selectedRows: this.selectedRows,   // 当前行所有数据
    //     onChange: this.onSelectChange
    //   }
    // }
  },
  methods: {
    // 审批信息
    handleApproveDetail(record) {
      this.visibleApprove = true
      this.businessId = record.projectId
    },
    search(val) {
      this.queryParam = val
      this.queryParam.isProjectPeople = 1
      if (!this.queryParam.statusCode) {
        this.queryParam.projectStatus = '1,2,3,4,5,6'
      }
      this.getProjectTotal()
      this.$refs.table.refresh(true)
    },
    getProjectTotal() {
      getProjectTotal(this.queryParam).then((res) => {
        this.totalDels = res.data
      })
    },

    handleDels(val) {
      //
      this.$router.push({ path: '/project/staffAdjust/list', query: { projectId: val.projectId, branchName: val.branchName, projectName: val.shortName, type: 0 } })
    },

    handleEdit(val) {
      this.$router.push({ path: '/project/staffAdjust/list', query: { projectId: val.projectId, branchName: val.branchName, projectName: val.shortName, type: 1 } })
    },

    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  }
}
</script>


